package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.ISchoolFragmentContract;
import com.clouddot.baipai.http.entity.response.getArcticListResponse;
import com.clouddot.baipai.http.entity.response.getSchoolInfoResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class SchoolFragmentPresenter extends BasePresenterImpl<ISchoolFragmentContract.IView, ISchoolFragmentContract.IModel> implements ISchoolFragmentContract.IPresenter {
    public SchoolFragmentPresenter(ISchoolFragmentContract.IView view, ISchoolFragmentContract.IModel model) {
        super(view, model);
    }

    @Override
    public void getScholInfo(String type) {
        Subscription subscription = mModel.getScholInfo("GetCmsByTitle", type)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getSchoolInfoResponse>() {
                               @Override
                               public void call(getSchoolInfoResponse response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getArcticeInfo(String type, int pageindex, int pagesize) {
        Subscription subscription = mModel.getArcticeInfo("QueryCmsPage", type, pageindex, pagesize)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<getArcticListResponse>() {
                               @Override
                               public void call(getArcticListResponse response) {
                                   mView.success(2, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }


}
